package api

import (
	"gitee.com/hust-ideas/little-genius-backend/model"
	"gitee.com/hust-ideas/little-genius-backend/service"
	"github.com/gin-gonic/gin"
)

// KeywordSavePost - 保存关键词模式
func KeywordsSavePost(c *gin.Context) {
	s := c.MustGet("service").(*service.ServiceContext)
	req := model.KeywordSaveReq{}
	if err := c.ShouldBindJSON(&req.Keyword); err != nil {
		c.JSON(400, gin.H{"error": err.Error()})
		return
	}
	req.UserId = c.MustGet("uid").(uint64)
	resp, err := s.KeywordSavePost(req, c.Request.Context())
	if err != nil {
		c.JSON(500, gin.H{"error": err.Error()})
		return
	}
	c.JSON(201, resp)
}
